/**

 @Name：layuiAdmin 主页控制台
 @Author：贤心
 @Site：http://www.layui.com/admin/
 @License：LPPL
    
 */


layui.define(function(exports){

  //区块轮播切换
  layui.use(['admin', 'carousel'], function(){
    var $ = layui.$,
    admin = layui.admin,
    carousel = layui.carousel,
    element = layui.element,
    device = layui.device();

    //轮播切换
    $('.layadmin-carousel').each(function(){
      var othis = $(this);
      carousel.render({
        elem: this,
        width: '100%',
        arrow: 'none',
        interval: othis.data('interval'),
        autoplay: othis.data('autoplay') === true,
        trigger: (device.ios || device.android) ? 'click' : 'hover',
        anim: othis.data('anim')
      });
    });

  });

  //项目总览
  layui.use('table', function(){
    var $ = layui.$,
    table = layui.table;
    
    //今日热搜
    table.render({
      elem: '#LAY-index-topSearch',
      url: 'http://nm.edongfanghong.com/qxt_top_search',
      page: true,
      cols: [[
        {type: 'numbers', fixed: 'left'},
        {field: 'name', title: '项目名称', minWidth: 100},
        {field: 'starTime', title: '开始时间', width: 140},
        {field: 'endTime', title: '结束时间', width: 140},
        {field: 'status', title: '状态', width: 100, templet: function(d) {
          if(d.status.value == 1){
            return `<span class="layui-badge layui-bg-orange">${d.status.name}</span>`;
          }else if(d.status.value == 2){
            return `<span class="layui-badge layui-bg-cyan">${d.status.name}</span>`;
          }else if(d.status.value == 3){
            return `<span class="layui-badge layui-bg-blue">${d.status.name}</span>`;
          }else if(d.status.value == 4){
            return `<span class="layui-badge">${d.status.name}</span>`;
          }else if(d.status.value == 5){
            return `<span class="layui-badge layui-bg-gray">${d.status.name}</span>`;
          }else if(d.status.value == 6){
            return `<span class="layui-badge layui-bg-green">${d.status.name}</span>`;
          }
        }},
        {field: 'userName', title: '负责人', width: 100}
      ]],
      skin: 'line'
    });

    //任务进度
    table.render({
      elem: '#LAY-index-schedule',
      url: 'http://nm.edongfanghong.com/qxt_top_schedule',
      page: true,
      cols: [[
        {type: 'numbers', fixed: 'left'},
        {field: 'channel', title: '渠道', minWidth: 100},
        {field: 'account', title: '账号', minWidth: 120},
        {field: 'jigou', title: '机构', minWidth: 120},
        {field: 'fagao', title: '发稿量', minWidth: 120},
        {field: 'yuedu', title: '阅读量'}
      ]],
      skin: 'line'
    });
  });
  

  layui.use(['table'], function(){
	  var $ = layui.$;
	  
	  //系统投放对比数据柱状图
	  var echnormcol = [];
	  var normcol = [
      {
        xAxis: {
          type: 'category',
          data: [

            '2023-10',
            '2023-11',
            '2023-12',
            '2024-01',
            '2024-01',
            '2024-02',
            '2024-03',
            '2024-04',
            '2024-05',
            '2024-06',
            '2024-08',

          ]
        },
        yAxis: {
          type: 'value'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130, 120, 200, 150, 80, 70, 110, 130],
            type: 'bar'
          }
        ]
      }
    ];
    var elemNormcol = $('#LAY-index-normcol').children('div');
    var renderNormcol = function(index){
      echnormcol[index] = echarts.init(elemNormcol[index]);
      echnormcol[index].setOption(normcol[index]);
      window.onresize = echnormcol[index].resize;
    }; 
    
    console.log('elemNormcol' , elemNormcol);
    if(!elemNormcol[0]) return;
    renderNormcol(0);

    var echnormcol2 = [];

    var bgColor = '#fff';
    var title = '总量';
    var color =['#c065e7','#765deb','#3862d8','#6a89E2','#219CF9','#6efbbf','#40c057','#ffd351','#ff8e43','#f56b6d'];
    var echartData = [{
      name: "抖音",
      value: "3720"
    },
    {
      name: "微信",
      value: "2920"
    },
    {
      name: "电子报纸",
      value: "2200"
    },
    {
      name: "微博",
      value: "1420"
    },
    {
      name: "E类",
      value: "3200"
    },
    {
      name: "头条",
      value: "2420"
    },
    {
      name: "百度",
      value: "2200"
    }
    // ,
    // {
    //   name: "H类",
    //   value: "1420"
    // },
    // {
    //   name: "I类",
    //   value: "3200"
    // },
    // {
    //   name: "J类",
    //   value: "2420"
    // }
    ];

    var formatNumber = function(num) {
      var reg = /(?=(\B)(\d{3})+$)/g;
      return num.toString().replace(reg, ',');
    };

    var total = echartData.reduce((a, b) => {
      return a + b.value * 1
    }, 0);

	  var normcol2 = [
      {
        backgroundColor: bgColor,
        color: color,
        tooltip: {
            trigger: 'item'
        },
        title: [{
          text: '{name|' + title + '}\n{val|' + formatNumber(total) + '}',
          top: 'center',
          left: 'center',
          textStyle: {
            rich: {
              name: {
                fontSize: 14,
                fontWeight: 'normal',
                color: '#000',
                padding: [10, 0]
              },
              val: {
                fontSize: 32,
                fontWeight: 'bolder',
                color: '#000',
              }
            }
          }
        },{
          text: '单位：个',
          top: 20,
          left: 20,
          textStyle: {
            fontSize: 14,
            color:'#666666',
            fontWeight: 400
          },
          show: false
        }],
        series: [{
          type: 'pie',
          roseType: 'radius',
          radius: ['25%', '60%'],
          center: ['50%', '50%'],
          data: echartData,
          hoverAnimation: false,
          itemStyle: {
            normal: {
              borderColor: bgColor,
              borderWidth: 2
            }
          },
          labelLine: {
            normal: {
              length: 20,
              length2: 120,
              lineStyle: {
                  // color: '#e6e6e6'
              }
            }
          },
          label: {
            normal: {
              formatter: params => {
                return (
                  '{icon|●}{name|' + params.name + '}\n{value|' +
                  formatNumber(params.value) + '}'
                );
              },
              // padding: [0 , -100, 25, -100],
              rich: {
                icon: {
                  fontSize: 16,
                  color: 'inherit'
                },
                name: {
                  fontSize: 18,
                  padding: [0, 0, 0, 10],
                  color: '#000'
                },
                value: {
                  fontSize: 14,
                  fontWeight: 'bolder',
                  padding: [10, 0, 0, 20],
                  color: 'inherit'
                  // color: '#333333'
                }
              }
            }
          },
        }]
      }
    ];
    var elemNormcol2 = $('#LAY-index-normcol2').children('div');
    var renderNormcol2 = function(index){
      echnormcol2[index] = echarts.init(elemNormcol2[index]);
      echnormcol2[index].setOption(normcol2[index]);
      window.onresize = echnormcol2[index].resize;
    }; 
    
    if(!elemNormcol2[0]) return;
    renderNormcol2(0);
  });
  
  exports('console', {})
});